<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Event
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 * @version    $Id: AdminManageController.php 9085 2011-07-21 21:12:14Z john $
 * @author     Jung
 */

/**
 * @category   Application_Extensions
 * @package    Event
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 */
class Event_AdminManageController extends Core_Controller_Action_Admin {
	public function indexAction() {
		$this->view->navigation = $navigation = Engine_Api::_ ()->getApi ( 'menus', 'core' )->getNavigation ( 'event_admin_main', array (), 'event_admin_main_manage' );
		
		if ($this->getRequest ()->isPost ()) {
			$values = $this->getRequest ()->getPost ();
			foreach ( $values as $key => $value ) {
				if ($key == 'delete_' . $value) {
					$event = Engine_Api::_ ()->getItem ( 'event', $value );
					$event->delete ();
				}
			}
		}
		
		$page = $this->_getParam ( 'page', 1 );
		$this->view->paginator = Engine_Api::_ ()->getItemTable ( 'event' )->getEventPaginator ( array ('orderby' => 'admin_id' ) );
		$this->view->paginator->setItemCountPerPage ( 25 );
		$this->view->paginator->setCurrentPageNumber ( $page );
	}
	
	public function deleteAction() {
		// In smoothbox
		$this->_helper->layout->setLayout ( 'admin-simple' );
		$id = $this->_getParam ( 'id' );
		$this->view->event_id = $id;
		// Check post
		if ($this->getRequest ()->isPost ()) {
			$db = Engine_Db_Table::getDefaultAdapter ();
			$db->beginTransaction ();
			
			try {
				$event = Engine_Api::_ ()->getItem ( 'event', $id );
				$event->delete ();
				$db->commit ();
			} 

			catch ( Exception $e ) {
				$db->rollBack ();
				throw $e;
			}
			
			$this->_forward ( 'success', 'utility', 'core', array ('smoothboxClose' => 10, 'parentRefresh' => 10, 'messages' => array ('' ) ) );
		}
		// Output
		$this->renderScript ( 'admin-manage/delete.tpl' );
	}
}